﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using cbmobile.BLC;
using PQT.API;
using cbmobile.DAC;

namespace cbmobile.UserControl
{
    public partial class LoaiLinhKien_Entry : CommonUserControl
    {
        BLC_LoaiPhuKien nBLC = new BLC_LoaiPhuKien();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["action"] != null)
                {
                    switch (Request.QueryString["action"].ToLower())
                    {
                        case "addnew": frmBlogCate.ChangeMode(FormViewMode.Insert);
                            break;
                     }
                }
            }
        }

        private void BindControlField()
        {
            LoaiPhuKien ent = nBLC.Get_LoaiPhuKien_By_ID(this.Ma_LoaiPhuKien);

            DropDownList ddlStatus = frmBlogCate.FindControl("ddlStatus") as DropDownList;
            if (ddlStatus != null)
            {
                ddlStatus.Items.Clear();

                ddlStatus.Items.Add(new ListItem(CommonStatus.Inactive.ToString(), ((int)CommonStatus.Inactive).ToString()));
                ddlStatus.Items.Add(new ListItem(CommonStatus.Active.ToString(), ((int)CommonStatus.Active).ToString()));

                if (ent != null)
                {
                    ddlStatus.SelectedValue = ent.TrangThai.ToString();
                }
            }
        }

        private DropDownList findcontrol_DropList(string findcontrol)
        {
            return frmBlogCate.FindControl(findcontrol) as DropDownList;
        }


        protected string StatusName(object StatusID)
        {
            return StatusID != null ? ((CommonStatus)StatusID).ToString() : string.Empty;
        }


        protected void frmBlogCate_ItemUpdating(object sender, ObjectDataSourceMethodEventArgs e)
        {
        }

        protected void frmBlogCate_ItemInserted(object sender, FormViewInsertedEventArgs e)
        {
            Response.Redirect(this.ListLink);
        }

        protected void frmBlogCate_ItemDeleted(object sender, FormViewDeletedEventArgs e)
        {
            Response.Redirect(this.ListLink);
        }

        protected void frmBlogCate_ItemInserting(object sender, FormViewInsertEventArgs e)
        {
        }


        protected void frmBlogCate_DataBound(object sender, EventArgs e)
        {
            BindControlField();
        }

        protected int Ma_LoaiPhuKien
        {
            get
            {

                return Utility.ValidateParam("Ma_LoaiPhuKien", 0);
            }
        }

        protected void ObjectDataSource1_Updating(object sender, ObjectDataSourceMethodEventArgs e)
        {
            DropDownList ddlStatus = frmBlogCate.FindControl("ddlStatus") as DropDownList;
            e.InputParameters["TrangThai"] = ddlStatus.SelectedValue;
        }

        protected void ObjectDataSource1_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
        {
            DropDownList ddlStatus = frmBlogCate.FindControl("ddlStatus") as DropDownList;
            e.InputParameters["TrangThai"] = ddlStatus.SelectedValue;
        }
    }
}